/*
 * Copyright (c) 2025 CAX Conversion Project
 */
package com.comac.ins.isfd.factory;

import com.comac.ins.common.core.exception.base.BaseException;
import com.comac.ins.isfd.constant.enums.IsfdSectionTypeEnum;
import com.comac.ins.isfd.service.IIsfdSectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 型材库实现工厂类
 *
 * @author hxloongs
 * @date 2024-7-29
 */
@Component
public class IsfdSectionFactory {

    @Autowired
    private List<IIsfdSectionService> iIsfdSectionServiceList;

    public IIsfdSectionService getSectionServiceByType(IsfdSectionTypeEnum isfdSectionTypeEnum) {
        if (isfdSectionTypeEnum == null) {
            throw new BaseException("型材类型不存在，请确认后重试！");
        }
        if (CollectionUtils.isEmpty(iIsfdSectionServiceList)) {
            throw new BaseException("型材类型不存在，请确认后重试！");
        }
        // 选择对应的型材类型实现类
        return iIsfdSectionServiceList.stream()
            .filter(item -> item.selectByType().equals(isfdSectionTypeEnum.getValue()))
            .findFirst()
            .orElseThrow(() -> new BaseException("型材类型不存在，请确认后重试！"));
    }
}
